using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

//商品
  public static class ProductDatabase
{
 public static List<Product> Products = new List<Product>
{
 new Product { Id = "1", Name = "干脆面", Stock = "20箱", Price = "4元/瓶" },
 new Product { Id = "2", Name = "营养快线", Stock = "15箱", Price = "3.5元/瓶" },
 new Product { Id = "3", Name = "优酸乳", Stock = "18箱", Price = "2元/瓶" },
 new Product { Id = "4", Name = "辣条", Stock = "18箱", Price = "3.5元/瓶" }
};
}

// 商品类
  public class Product
{
  public string Id { get; set; } = "null";
  public string Name { get; set; } = "null";
  public string Stock { get; set; } = "null";
  public string Price { get; set; } = "null";
}

  namespace ShopForWeb.UI.Controllers.Text
{
   [Route("Job/Job")]
  public class JobController : Controller
{
  public JobController()
 {
 }

    // 查询商品详情：根据商品 ID 查询商品详情
  [HttpGet("{jobId}")]
   public IActionResult GetProduct([FromRoute] string jobId)
 {
    var product = ProductDatabase.Products.FirstOrDefault(p => p.Id == jobId);
    if (product == null)
 {
   return NotFound();
 }
   return Json(product);
 }

    // 查询商品列表：分页查询所有商品列表
  [HttpGet("list")]
  public IActionResult GetProductList([FromQuery] int page = 1, [FromQuery] int pageSize = 10)
{
   var startIndex = (page - 1) * pageSize;
   var products = ProductDatabase.Products.Skip(startIndex).Take(pageSize).ToList();
   return Json(products);
 }

    // 查询商品的价格和数量：根据商品 ID 查询商品的价格和库存数量
  [HttpGet("{jobId}/price-stock")]
   public IActionResult GetProductPriceAndStock([FromRoute] string jobId)
 {
     var product = ProductDatabase.Products.FirstOrDefault(p => p.Id == jobId);
     if (product == null)
 {
     return NotFound();
 }
     return Json(new { Price = product.Price, Stock = product.Stock });
 }
   [HttpDelete("{jobId}")]
   public IActionResult RemoveProduct([FromRoute] string jobId)
{
     var product = ProductDatabase.Products.FirstOrDefault(p => p.Id == jobId);
     if (product == null)
{
    return NotFound();
}
    ProductDatabase.Products.Remove(product);
    return Json(new { Message = $"{jobId}-删除成功" });
 }
 }
}


 // 删除商品：根据商品 ID 删除一个商品